/*
 * Copyright (c) 2010 Subodh.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
 * 
 * 
DISCLAIMER: ilangl.Customer.DNN template is not affiliated nor endorsed by DNN Corp. 
 */
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web.UI.WebControls;
using System.Xml;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Data;
using DotNetNuke.Entities.Host;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Entities.Users;
using DotNetNuke.Framework;
using DotNetNuke.Security;
using DotNetNuke.Security.Permissions;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using DotNetNuke.Services.Log.EventLog;
using DotNetNuke.UI.Skins;
using DotNetNuke.UI.Skins.Controls;
using DotNetNuke.UI.Utilities;
using DotNetNuke.Web.UI;
using Telerik.Web.UI;
using DataCache = DotNetNuke.Common.Utilities.DataCache;
using Globals = DotNetNuke.Common.Globals;
using iLangl.Customer.DNN.Components;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Web.UI.WebControls;
using iLangl.Customer.DNN.Presenters;
using iLangl;



namespace iLangl.Customer.DNN
{
	public partial class MainContol : DnnModuleBase
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			
			if (!IsPostBack)
			{
				updatePanels();
				UserInfo ui = UserController.GetCurrentUserInfo();
				if(ui != null)
					this.lblUserName.Text = ui.DisplayName;

				TreeViewPresenter presenter = new TreeViewPresenter(this);
				presenter.bindTree(ctlProjects);
				presenter.FillByStatus(ProjectStatuses.Configuration, ctlProjects);
				
			}
		}

		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);

			ctlProjects.NodeClick += new RadTreeViewEventHandler(ctlProjects_NodeClick);
		}

		public string GetConfirmString()
		{
			return Localization.GetString("ConfirmDelete", LocalResourceFile);
		}

		void ctlProjects_NodeClick(object sender, RadTreeNodeEventArgs e)
		{
			updatePanels(e);
		}


		#region Controller Methods
		private void updatePanels()
		{
			HideAllPanels();
			if (!RegistrationManager.Instance.IsPluginRegistered(this.SiteId))
			{
				pnlNotRegistered.Visible = true;
				return;
			}
		}
		private void updatePanels(RadTreeNodeEventArgs e)
		{
			updatePanels();
			if (e.Node.Level == 0)
			{

				pnlDashboardView.Visible = true;
			}
			else if (e.Node.Level == 1)
			{

				pnlStateView.Visible = true;
			}
			else
			{
				pnlProjectView.Visible = true;
			}
		}

		protected void HideAllPanels()
		{
			pnlDashboardView.Visible = false;
			pnlProjectView.Visible = false;
			pnlStateView.Visible = false;
			pnlNotRegistered.Visible = false;
		}
		#endregion

		

		
		protected RadTreeNode GetStateNode(String resourceKey)
		{
			var node = new RadTreeNode() { Text = GetLocalizedString(resourceKey) };
			node.Expanded = true;
			node.AllowEdit = false;
			node.ImageUrl = GetIcon(IconManager.SecuredIcon);
			node.EnableContextMenu = true;
			node.Attributes.Add("StateNode", "true");
			return node;
		}

		public override ModuleActionCollection ModuleActions
		{
			get
			{
				//if(RegistrationManager.Instance.IsPluginRegistered())
				MyActions.Add(this.GetNextActionID(), GetLocalizedString("NewProject"), "EditProject.Action", "", "", this.EditUrl("NewProject"), false, SecurityAccessLevel.Admin, true, false);

				MyActions.Add(this.GetNextActionID(), GetLocalizedString("Registration"), "EditProject.Action", "", "", this.EditUrl("Registration.Action"), false, SecurityAccessLevel.Admin, true, false);
				
				return MyActions;
			}
		}
	}
}